package com.oceansoft.mobile.econsole.modules.weixin.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import com.oceansoft.mobile.econsole.common.util.HttpClientUtil;
import com.oceansoft.mobile.econsole.modules.base.controller.BaseController;
import com.oceansoft.mobile.econsole.modules.member.entity.WtMember;
import com.oceansoft.mobile.econsole.modules.weixin.config.WxFactory;
import com.oceansoft.mobile.econsole.modules.weixin.service.ILostPropertyService;
import com.oceansoft.mobile.econsole.weixin.api.OauthAPI;
import com.oceansoft.mobile.econsole.weixin.api.enums.OauthScope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import java.io.IOException;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
 * 查询办事\
 * 办事咨询
 */
@Controller
@RequestMapping("weixin/bszx")
public class BszxController extends BaseController {

    /**
     * 我要提问
     */
    @RequestMapping(value = "askQuestion")
    public String gotoRegister_protocolIndex(HttpServletRequest request,Model model) {
        if(null!=getWxMemberSession()) {
           String guid= request.getParameter("userGuid");
           if(Strings.isNullOrEmpty(guid)){
               model.addAttribute("member",getWxMemberSession());
               model.addAttribute("pt",request.getParameter("pt"));
               return "weixin/bszx/AskQuestion";
           }else{
               String resu = "";
               try {
                   resu = HttpClientUtil.doGet(configInfo.getServiceInterfaceAddress() + "/member/" + guid);
               } catch (IOException e) {
                   e.printStackTrace();
               }
               JSONObject jsonobject = JSON.parseObject(resu);
               WtMember wtMember = JSON.parseObject(jsonobject.getString("data"), WtMember.class);
               model.addAttribute("wtMember",wtMember);
               model.addAttribute("pt",request.getParameter("pt"));
               return "weixin/bszx/AskQuestion";
           }

        }else {
            OauthAPI oauthAPI = WxFactory.buildOauthAPI();
            return "redirect:" + oauthAPI.getOauthPageUrl(WxFactory.PERCENTER_OAUTH_URL, OauthScope.SNSAPI_BASE, "123");
        }
    }

    /**
     * 我的咨询
     */
    @RequestMapping(value = "myconsulting")
    public String gotoRegisterIndex(Model model) {
        model.addAttribute("member",getWxMemberSession());
        return "weixin/bszx/Myconsulting";
    }






}
